package com.SuanFa.jiangdongqi.QiuZuiDaLianXuShuZu;

/**
 * 求最大连续数组
 */
public class aaa {
    public static void main(String[] args) {
//        int [] nums ={3,4,3,7,5,8,4,7,3,45,89,23,7,64,3,2,57,8,66,5};
        int [] nums={5,4,-1,7,8};
        int i1 = maxSubArray(nums);
        System.out.println(i1);
    }
    public static int maxSubArray(int[] nums) {
           int n = nums.length;
           int maxnum = 0,temp;
           if (nums.length==1){
               return nums[0];
           }
        for (int i = 0; i < n; i++) {
            temp=0;
            for (int j = i; j <n ; j++) {
                temp+=nums[j];
                maxnum=Math.max(maxnum,temp);
            }
        }
        return maxnum;
    }
}
